home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gnome2-desktop / examples / gnomeprint / example_04.py < prev    next >
Encoding:
Python Source  |  2009-03-14  |  2.4 KB  |  89 lines

  1. #! /usr/bin/env python
  2. #
  3. # *  example_04.c: sample gnome-print code
  4. # *
  5. # *  This program is free software; you can redistribute it and/or
  6. # *  modify it under the terms of the GNU Library General Public License
  7. # *  as published by the Free Software Foundation; either version 2 of
  8. # *  the License, or (at your option) any later version.
  9. # *
  10. # *  This program is distributed in the hope that it will be useful,
  11. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # *  GNU Library General Public License for more details.
  14. # *
  15. # *  You should have received a copy of the GNU Library General Public
  16. # *  License along with this program; if not, write to the Free Software
  17. # *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. # *
  19. # *  Authors:
  20. # *    Chema Celorio <chema@ximian.com>
  21. #    Python conversion:
  22. #      Gustavo J. A. M. Carneiro <gustavo@users.sf.net>
  23. # *
  24. # *  Copyright (C) 2002 Ximian Inc. and authors
  25. # *
  26. # */
  27.  
  28. #/*
  29. # * See README
  30. # */
  31.  
  32. import pygtk; pygtk.require("2.0")
  33. import gnomeprint
  34.  
  35.  
  36. def my_draw(gpc):
  37.     # Make some UTF-8 strings
  38.     acented = "".join(map(chr, (0xC3, 0xA0, 0xC3, 0xA8, 0xC3, 0xAC,
  39.                 0xC3, 0xB2, 0xC3, 0xB9, 0x20, 0xC3,
  40.                 0xB1, 0xC3, 0x91, 0x20, 0xC3, 0xBB,
  41.                 0xC3, 0xB4, 0x20)))
  42.     
  43.     cyrillic = "".join(map(chr, (0xD0, 0xA1, 0xD0, 0xBE, 0xD0, 0xBC, 0xD0, 0xB5,
  44.                  0x20, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xBD,
  45.                  0xD0, 0xB4, 0xD0, 0xBE, 0xD0, 0xBC, 0x20, 0xD1,
  46.                  0x86, 0xD1, 0x8B, 0xD1, 0x80, 0xD1, 0x83,
  47.                  0xD0, 0xBB, 0xD0, 0xBB, 0xD0, 0xB8, 0xD1, 0x86,
  48.                  0x20, 0xD1, 0x87, 0xD0, 0xB0, 0xD1, 0x80,
  49.                  0xD1, 0x81)))
  50.  
  51.     # Get this font from:
  52.     #   http://bibliofile.mc.duke.edu/gww/fonts/Unicode.html
  53.     # I used the TTF Caslon Roman.
  54.  
  55.     font = gnomeprint.font_find_closest("Caslon Roman", 12)
  56.     font_name = font.get_name()
  57.     print "Found:", font_name
  58.     if font_name != "Caslon Roman":
  59.     print "You might not see cyrillic characters because Caslon Roman was not found.\n"
  60.     
  61.     gpc.beginpage("1")
  62.  
  63.     gpc.setfont(font)
  64.     
  65.     gpc.moveto(100, 700)
  66.     gpc.show("Some acented characters:")
  67.     gpc.moveto(100, 680)
  68.     gpc.show(acented)
  69.  
  70.     gpc.moveto(100, 650)
  71.     gpc.show("Some cyrillic:")
  72.     gpc.moveto(100, 630)
  73.     gpc.show(cyrillic)
  74.  
  75.     gpc.showpage()
  76.  
  77. def my_print():
  78.     job = gnomeprint.Job(gnomeprint.config_default())
  79.     gpc = job.get_context()
  80.  
  81.     my_draw(gpc)
  82.  
  83.     job.close()
  84.     job.print_()
  85.  
  86. my_print()
  87. print "Done..."
  88.  
  89.